package com.example.demo.service;

import com.example.demo.main.UserCart;
import com.example.demo.main.UserCartExample;
import com.example.demo.mapper.UserCartMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UseSQLByCart {

    @Autowired
    private UserCartMapper userCartMapper;
    @Autowired
    private UserCartExample userCartExample;

    public Integer insertByClass(UserCart userCart) {
        return userCartMapper.insertSelective(userCart);
    }

    public List<UserCart> selectByGoodsName(String name) {
        userCartExample.clear();
        userCartExample.or().andGoodsNameEqualTo(name);
        return userCartMapper.selectByExample(userCartExample);
    }


    public List<UserCart> selectByUserName(String name) {
        userCartExample.clear();
        userCartExample.or().andUserNameEqualTo(name);
        return userCartMapper.selectByExample(userCartExample);
    }

    public Integer updateByClass(UserCart userCart) {
        return userCartMapper.updateByPrimaryKeySelective(userCart);
    }
}
